#ifndef __POSTED_SIGN_BLOCK_H__
#define __POSTED_SIGN_BLOCK_H__

#include "Block.hpp"
#include "IPaintableBlock.hpp"

namespace PocketSurvival
{
    // 杆牌子方块基类
    class PostedSignBlock : public Block, public IPaintableBlock
    {
	public:
		int32_t attachedSignBlockIndex;
    public:
		PostedSignBlock(int32_t attachedSign);
        virtual void getCreativeValues(std::vector<int32_t> &blockVec) override;
        virtual void getDropValues(int32_t oldValue, int32_t newValue, int32_t toolLevel, std::vector<BlockDropValue> &dropValues) override;
        virtual BlockPlacementData getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult) override;

        virtual int32_t getPaintColor(int32_t value) override;
        virtual int32_t paint(int32_t value, int32_t color) override;

		static inline int32_t GetDirection(int32_t data);
		static inline int32_t SetDirection(int32_t data, int32_t direction);
        static inline int32_t GetColor(int32_t data);
        static inline int32_t SetColor(int32_t data, int32_t color);
		static inline int32_t GetVariant(int32_t data);
		static inline int32_t SetVariant(int32_t data, int32_t variant);
		static inline bool GetHanging(int32_t data);
		static inline int32_t SetHanging(int32_t data, bool hanging);

    };

	inline int32_t PostedSignBlock::GetDirection(int32_t data)
	{
		return data & 7;
	}
	inline int32_t PostedSignBlock::SetDirection(int32_t data, int32_t direction)
	{
		return (data & -8) | (direction & 7);
	}
	inline bool PostedSignBlock::GetHanging(int32_t data)
	{
		return (data & 8) != 0;
	}
	inline int32_t PostedSignBlock::SetHanging(int32_t data, bool hanging)
	{
		if (!hanging)
		{
			return data & -9;
		}
		return data | 8;
	}
    inline int32_t PostedSignBlock::GetColor(int32_t data)
    {
		if ((data & 0x10) != 0)
		{
			return (data >> 5) & 0xF;
		}
		return -1;
    }
    inline int32_t PostedSignBlock::SetColor(int32_t data, int32_t color)
    {
		if (color != -1)
		{
			return (data & -497) | 0x10 | ((color & 0xF) << 5);
		}
		return data & -497;
    }
	inline int32_t PostedSignBlock::GetVariant(int32_t data)
	{
		return data & 0xF;
	}
	inline int32_t PostedSignBlock::SetVariant(int32_t data, int32_t variant)
	{
		return (data & -16) | (variant & 0xF);
	}

} // namespace PocketSurvival


#endif
